package com.wyg.command;

/**
 * @description:
 * @author: WYG
 * @time: 2021/3/30 8:48
 */

public class SimpleRemoteCommand {
    private Command slot;
    private Command undoCommand;

    public SimpleRemoteCommand() {
        Command noCommand = new NoCommand();
        undoCommand = noCommand;
    }

    public void setCommand(Command command) {
        slot = command;
    }
    public void buttonWasPressed() {
        slot.execute();
        undoCommand = slot;
    }

    public void buttonOffWasPushed() {
        slot.execute();
        undoCommand = slot;
    }

    public void undoButtonWasPushed() {
        undoCommand.undo();
    }

    public static void main(String[] args) {
        SimpleRemoteCommand remoteCommand = new SimpleRemoteCommand();
        Light light = new Light();
        LightOnCommand lightOnCommand = new LightOnCommand(light);
        remoteCommand.setCommand(lightOnCommand);
        remoteCommand.buttonWasPressed();
        remoteCommand.undoButtonWasPushed();
    }
}
